package com.uzai.console.web.ks;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.ks.kstoken.KsTokenIdDto;
import com.uzai.console.dto.ks.kstoken.KsTokenInfoDto;
import com.uzai.console.dto.ks.kstoken.KsTokenQuery;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenIdDto;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenInfoDto;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenQuery;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.ks.KsTokenService;
import com.uzai.console.service.locallive.TlbTokenService;
import com.uzai.console.vo.ks.kstoken.KsTokenAuthUrlVo;
import com.uzai.console.vo.ks.kstoken.KsTokenInfoVo;
import com.uzai.console.vo.locallive.tlbtoken.TlbTokenInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 快手联盟
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "快手联盟",tags = "快手|快手联盟")
@ApiSort(10)
@RestController
public class KsTokenController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(KsTokenController.class);

    @Autowired
    private TlbTokenService tlbTokenService;
    @Autowired
    private KsTokenService ksTokenService;

    @ApiOperation(value = "分页查询快手联盟列表", notes = "分页查询快手联盟列表", response = KsTokenInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/ksToken/findKsTokenList")
    public Object findKsTokenList(@RequestBody KsTokenQuery ksTokenQuery){
        return ksTokenService.findKsTokenList(ksTokenQuery);
    }

    @ApiOperation(value = "查询快手联盟详情", notes = "查询快手联盟详情", response = KsTokenInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/ksToken/findKsTokenInfo")
    public Object findKsTokenInfo(@RequestBody KsTokenIdDto ksTokenIdDto){
        return ksTokenService.findKsTokenInfo(ksTokenIdDto);
    }
    
    @SystemLogType(model = SystemModelEnum.KsToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加快手联盟", notes = "添加快手账号", response = KsTokenAuthUrlVo.class)
    @ApiOperationSupport(order = 13)
    @PostMapping("/ksToken/addKsTokenAuth")
    public Object addKsTokenAuth(){
        return ksTokenService.addKsToken(getLoginInfo().getMerId());
    }

    @SystemLogType(model = SystemModelEnum.KsToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改快手联盟", notes = "修改快手账号")
    @ApiOperationSupport(order = 14)
    @PostMapping("/ksToken/updateKsTokenAuth")
    public Object updateKsTokenAuth(@RequestBody KsTokenInfoDto ksTokenInfoDto){
        ksTokenService.updateKsToken(ksTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.KsToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除快手联盟", notes = "删除快手账号")
    @ApiOperationSupport(order = 5)
    @PostMapping("/ksToken/deleteKsTokenAuth")
    public Object deleteKsTokenAuth(@RequestBody KsTokenIdDto ksTokenInfoDto){
        ksTokenService.deleteKsToken(ksTokenInfoDto);
        return true;
    }

    @ApiOperation(value = "分页查询推老板快手联盟列表", notes = "分页查询推老板快手联盟列表", response = TlbTokenInfoVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/ksToken/findTlbTokenList")
    public Object findTlbTokenList(@RequestBody TlbTokenQuery tlbTokenQuery){
        tlbTokenQuery.setType("ks");
        return tlbTokenService.findTlbTokenList(tlbTokenQuery);
    }

    @ApiOperation(value = "分页查询推老板快手联盟详情", notes = "分页查询推老板快手联盟详情", response = TlbTokenInfoVo.class)
    @PostMapping("/ksToken/findTlbTokenInfo")
    public Object findTlbToken(@RequestBody TlbTokenIdDto tlbTokenIdDto){
        return tlbTokenService.findTlbTokenInfo(tlbTokenIdDto);
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加推老板快手联盟", notes = "添加推老板快手联盟")
    @ApiOperationSupport(order = 8)
    @PostMapping("/ksToken/addTlbToken")
    public Object addTlbToken(@RequestBody TlbTokenInfoDto tlbTokenInfoDto){
        if(StringUtils.isBlank(tlbTokenInfoDto.getType())){
            tlbTokenInfoDto.setType("ks");
        }

        tlbTokenService.addTlbToken(tlbTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改推老板快手联盟", notes = "修改推老板快手联盟")
    @ApiOperationSupport(order = 9)
    @PostMapping("/ksToken/updateTlbToken")
    public Object updateTlbToken(@RequestBody TlbTokenInfoDto tlbTokenInfoDto){
        tlbTokenService.updateTlbToken(tlbTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除推老板快手联盟", notes = "删除推老板快手联盟")
    @ApiOperationSupport(order = 10)
    @PostMapping("/ksToken/deleteTlbToken")
    public Object deleteTlbToken(@RequestBody TlbTokenIdDto tlbTokenIdDto){
        tlbTokenIdDto.setType("ks");
        tlbTokenService.deleteTlbToken(tlbTokenIdDto);
        return true;
    }

    @ApiOperation(value = "查询所有推老板快手联盟列表", notes = "查询所有推老板快手联盟列表", response = TlbTokenInfoVo.class)
    @ApiOperationSupport(order = 12)
    @PostMapping("/ksToken/findTlbKsTokenListSelect")
    public Object findTlbKsTokenListSelect(@RequestBody TlbTokenQuery tlbTokenQuery){
        tlbTokenQuery.setType("ks");
        return tlbTokenService.findTlbTokenListSelect(tlbTokenQuery);
    }

}
